/*
package com.tanhua.server.interceptor;

import com.tanhua.server.pojo.Manage;
import com.tanhua.server.pojo.User;
import com.tanhua.server.service.UserService;
import com.tanhua.server.utils.ManageThreadLocal;
import com.tanhua.server.utils.NoAuthorization;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


*/
/**
 * 统一完成根据token查询用User的功能
 *//*

@Component
@Slf4j
public class TokenInterceptor implements HandlerInterceptor {

    @Autowired
    private UserService userService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (!(handler instanceof HandlerMethod))
            return true;
        if (((HandlerMethod)handler).hasMethodAnnotation(NoAuthorization.class)) {
            return true;
        }
        try {
            String token = request.getHeader("Authorization");
            String[] tokenArr = token.split(" ");
            token = tokenArr[1];
            Manage manage = userService.queryUserByToken(token);
            if (manage == null)
                return false;
            ManageThreadLocal.set(manage);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        //请求头中如不存在Authorization直接返回false
        response.setStatus(401); //无权限访问
        return false;
    }
}
*/
